package com.lam.generator.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lam.common.utils.StringUtils;
import com.lam.generator.entity.GenTableColumn;
import com.lam.generator.mapper.GenTableColumnMapper;
import com.lam.generator.service.GenTableColumnService;

/**
 * 代码生成字段Service业务层处理
 * 
 * @author admin
 * @date 2022-09-26
 */
@Service
public class GenTableColumnServiceImpl implements GenTableColumnService {

    @Autowired
    private GenTableColumnMapper genTableColumnMapper;

    /**
     * 查询代码生成字段列表
     * 
     * @param param
     * @return 
     */
    @Override
    @Transactional(readOnly = true)
    public List<GenTableColumn> selectListByTableId(String tableId) {
    
        QueryWrapper<GenTableColumn> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("table_id", tableId);
        queryWrapper.orderByAsc("sort");
        return genTableColumnMapper.selectList(queryWrapper);
    }

    /**
     * 新增代码生成字段
     * 
     * @param genTableColumn 
     * @return 
     */
    @Override
    @Transactional
    public int insert(GenTableColumn genTableColumn) {
    
        return genTableColumnMapper.insert(genTableColumn);
    }

    /**
     * 修改代码生成字段
     * 
     * @param genTableColumn 
     * @return 
     */
    @Override
    @Transactional
    public int update(GenTableColumn genTableColumn) {
    
        return genTableColumnMapper.updateById(genTableColumn);
    }
    
    /**
     * 删除代码生成字段信息
     * @param idStr ID，多个用逗号分隔
     * @return 
     */
    @Override
    @Transactional
    public int deleteById(List<String> idList) {
    	
        return genTableColumnMapper.deleteBatchIds(idList);
    }
    
    /**
     * 根据表Id删除代码生成字段信息
     * 
     * @param tableId 表Id
     * @return 
     */
    @Override
    @Transactional
    public int deleteByTableId(String tableId) {
    	
        QueryWrapper<GenTableColumn> queryWrapper = new QueryWrapper<>();
        if(tableId.contains(",")) {
        	queryWrapper.in("table_id", StringUtils.str2List(tableId));
        }else {
        	queryWrapper.eq("table_id", tableId);
        }
		return genTableColumnMapper.delete(queryWrapper);
    }
    
    
}
